<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of sobjectproduce
 *
 * @author Dragon.hu add @2015.9.22
 */
defined('BASEPATH') or die('forbidden');

class Fashion_Controller extends Controller {

	private $inc;
	private $logdb;	//数据库连接
	private $platformList;	//平台列表
	
	function _init() {
		check_level(50, segment(0), segment(1), segment(2, 'index'));
		set_time_limit(0);
		
		$this->inc = $this->config['inc'];
		$this->platformList = $this->inc['platform_list'];
		
        // log数据库
		//$this->logdb = $this->load->database('log_db');
		//得到选择的区号
		$areanum = $_SESSION['area_selected_id'];
		if ($areanum == '')
		{
			echo "<script>alert('" . translate('C_SELECT_AREA_TEXT') . "');</script>";
			return;
		}
		// log数据库
        $this->logdb = $this->load->database('log_db');
        //$this->logdb = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_LOG);
		if (false == $this->logdb) {
			//内部有提示错误，在此就不提示了
			 //echo "<script>alert(' connect areanum:$areanum error ');</script>";
            return;
		}
	}

	function index() {
		$this->view->display("log_object/fashion/index");
	}

	function flexigrid() {
		list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();
        $orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";

		$areanum = $_SESSION['area_selected_id'];
        if ($where == ""){
        	$where = "svrid=" . $areanum;
        }else{
        	$where = "svrid=" . $areanum . " and (" . $where . ")"; 
        }

        $mapAreaNum = ((int)$areanum)%5+1;
        //$table_name = "gamelog_13_".$mapAreaNum;
		$table_name = "gamelog_13";

        $sql = "SELECT COUNT(*) AS num FROM {$table_name} where {$where} ";
        $one = $this->logdb->one($sql);
        $total=$one['num'];

        $sql1 = "SELECT {$colsinfo} FROM {$table_name} where {$where}  {$orderby} LIMIT {$offset},{$rp}";
        $this->logdb->query($sql1);
        $result1=$this->logdb->row('default');

        foreach ($result1 as $k=>$n){
            $n['time']=date('Y/m/d H:i:s',$n['time']);
            $n['eventid']=$this->config['event'][$n['eventid']];
            $n['srcid']=$this->config['source'][$n['srcid']];
            $n['type']=$this->config['chtype'][$n['type']];
            $n['extra']=($n['param2']>>32) & 0x00000000ffffffff;
            $n['param2'] = $n['param2'] & 0x00000000ffffffff;
            $rows[] = array('id' => $n['id'], 'cell' => $n);
        }
        $result = array(
            'page' => $page,
            'total' => $total,
            'rows' => $rows
        );

        echo json_encode($result);
	}

}
